20. Run the Game!
Run the game!
1. Edit Run Configurations
Right now, there is a lot of code in this project and IntelliJ needs to be told what to run. To tell it to run Game.java, you need to go to Run > Edit Configurations, and set up a New configuration.
Edit config drop down menu
step 2
Then in the Run Configurations window, click the +
button at the top left of this window to add a new configuration, and select Application.
Select new application
step 3
Then you'll see this configurations window, and the first thing you want to do is to name your configuration, and I'll name this Run Game.
Then you'll see the four fields that we've seen before:
- The main class that we want to run.
- The project directory for Project 1 - TicTacToe.
- The classpath of the module.
- The version of Java you're using.
You'll want to make sure these are all set to the correct fields before moving on and running the game. You'll also need to select the correct main class and module; the project directory and version of Java should be automatically chosen by IntelliJ.
So, after changing the name, the first thing you should select is the Main class by clicking the ...
to the side of the Main class field. Then, a window will prompt you to select the Game class. Select this and click Okay.
Main class, Game.java
step 4
Next select the correct module by using the drop-down menu to the right of this field, and choose the Project_1_-_TicTacToe_main module. Make sure you select the main module and not the test or default project modules.
Module selection
step 5
So, your final configuration should have the following fields:
- The main class that we want to run should be com.udacity.Game.
- The project directory for Project 1 - TicTacToe (left as is).
- The classpath of the module, which should be Project_1_-_TicTacToe_main.
- The version of Java you're using, which should be version 8.
Correct run config
step 6
Make sure all of these fields are correct and match the picture before proceeding.
After you've named and set your configuration to run Game.java, click Apply then Okay to get back to your program.
Apply button
step 6 plus
2. Run the Game!
After your run configuration is set up, you should see it's name appear in the top right of your screen next to the Run button. Now, you can simply click this button and Game.java will run.
Run Game
running 1
When you click Run, you should see a tic tac toe grid appear!
Tic tac toe grid
tic tac toe grid
You can even play a one or two player game of Tic Tac Toe, but this game code does not yet detect when a player wins!